﻿<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>MinuteClinic-一分钟网上诊所管理系统</title>
	<!-- Fav  Icon Link -->
	<link rel="shortcut icon" type="image/png" th:href="@{../images/fav.png}">
	<!-- Bootstrap core CSS -->
	<link rel="stylesheet" th:href="@{../css/bootstrap.min.css}">
	<!-- themify icons CSS -->
	<link rel="stylesheet" th:href="@{../css/themify-icons.css}">
	<!-- Animations CSS -->
	<link rel="stylesheet" th:href="@{../css/animate.css}">
	<!-- Main CSS -->
	<link rel="stylesheet" th:href="@{../css/styles.css}">
	<link rel="stylesheet" th:href="@{../css/green.css}" id="style_theme">
	<link rel="stylesheet" th:href="@{../css/responsive.css}">
	<!-- morris charts -->
	<link rel="stylesheet" th:href="@{../charts/css/morris.css}">
	<!-- jvectormap -->
	<link rel="stylesheet" th:href="@{../css/jquery-jvectormap.css}">
	<link rel="stylesheet" th:href="@{../datatable/dataTables.bootstrap4.min.css}">

	<script th:src="@{../js/modernizr.min.js}"></script>
</head>

<body>
<!-- Pre Loader -->
<div class="loading">
	<div class="spinner">
		<div class="double-bounce1"></div>
		<div class="double-bounce2"></div>
	</div>
</div>
<!--/Pre Loader -->
<!-- Color Changer -->
<div class="theme-settings" id="switcher">
		<span class="theme-click">
			<span class="ti-settings"></span>
		</span>
	<span class="theme-color theme-default theme-active" data-color="green"></span>
	<span class="theme-color theme-blue" data-color="blue"></span>
	<span class="theme-color theme-red" data-color="red"></span>
	<span class="theme-color theme-violet" data-color="violet"></span>
	<span class="theme-color theme-yellow" data-color="yellow"></span>
</div>
<!-- /Color Changer -->
<div class="wrapper">
	<!-- Page Content -->
	<div id="content">
		<!-- Top Navigation -->
		<div class="container top-brand">
			<nav class="navbar navbar-default">
				<div class="navbar-header">
					<div class="sidebar-header"> <a href="index.html"><img th:src="@{../images/logo-dark.png}" class="logo" alt="logo"></a>
					</div>
				</div>
				<ul class="nav justify-content-end">
					<li class="nav-item">
						<a class="nav-link">
							<span title="Fullscreen" class="ti-fullscreen fullscreen"></span>
						</a>
					</li>
					<li class="nav-item">
						<a class="nav-link dropdown-toggle" id="userinfo" data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
						   aria-expanded="false">
							<span class="ti-announcement"></span>
						</a>
						<div class="dropdown-menu lochana-box-shadow2 notifications animated flipInY">
							<h5>Notifications</h5>
							<a class="dropdown-item" href="#">
								<span class="ti-wheelchair"></span> 新增[[*{totals}]]位病人</a>
						</div>
					</li>
					<li class="nav-item">
						<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
						   aria-expanded="false">
							<span class="ti-user"></span>
						</a>
						<div class="dropdown-menu lochana-box-shadow2 profile animated flipInY">
							<h5><span id="username">[[${session.sessionValue}]]</span></h5>
							<a class="dropdown-item" href="/logout">
								<span class="ti-power-off"></span> Logout</a>

						</div>
					</li>
				</ul>

			</nav>
		</div>
		<!-- /Top Navigation -->
		<!-- Menu -->
		<div class="container menu-nav">
			<nav class="navbar navbar-expand-lg lochana-bg text-white">
				<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
						aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
					<span class="ti-menu text-white"></span>
				</button>

				<div class="collapse navbar-collapse" id="navbarSupportedContent">
					<ul class="navbar-nav mr-auto">
						<li class="nav-item dropdown">
							<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
							   aria-expanded="false"><span class="ti-home"></span> 个人面板</a>
							<div class="dropdown-menu">
								<a class="dropdown-item" href="/doctor/doctorUser">医生</a>
							</div>
						</li>
						<li class="nav-item dropdown">
							<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
							   aria-expanded="false"><span class="ti-wheelchair"></span> 病人信息</a>
							<div class="dropdown-menu">
								<a class="dropdown-item" href="/doctor/patients">病人信息</a>
							</div>
						</li>
						<li class="nav-item dropdown">
							<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
							   aria-expanded="false"><span class="ti-file"></span> 其它页面</a>
							<div class="dropdown-menu">
								<a class="dropdown-item" href="/index">主页</a>
								<a class="dropdown-item" href="/login">登录</a>
								<a class="dropdown-item" href="/view/modifyPwd">忘记密码</a>
							</div>
						</li>
					</ul>
				</div>
			</nav>
		</div>
				<div class="container mt-0">
					<div class="row breadcrumb-bar">
						<div class="col-md-6">
							<h3 class="block-title">医生</h3>
						</div>
						<div class="col-md-6">
							<ol class="breadcrumb">
								<li class="breadcrumb-item">
									<a href="index.html">
										<span class="ti-home"></span>
									</a>
								</li>
								<li class="breadcrumb-item">个人面板</li>
								<li class="breadcrumb-item active">医生信息 List</li>
							</ol>
						</div>
					</div>
				</div>
		<!-- /Breadcrumb -->
		<!-- Main Content -->
		<div class="container">

			<div class="row">
				<!-- Widget Item -->
				<div class="col-md-12">
					<div class="widget-area-2 lochana-box-shadow">
						<h3 class="widget-title">Edit 医生</h3>
						<form name="doctor_form">
							<div class="form-row">
								<div class="form-group col-md-6">
									<label for="name">医生姓名</label>
									<input type="text" value="" class="form-control" placeholder="医生姓名" id="name">
								</div>
								<div class="form-group col-md-6">
									<label for="idnumber">身份证</label>
									<input type="text" value="" placeholder="身份证" class="form-control" id="idnumber">
								</div>
								<div class="form-group col-md-6">
									<label for="sex">性别</label>
									<select class="form-control" id="sex">
										<option selected value="男">男</option>
										<option value="女">女</option>
									</select>
								</div>
								<div class="form-group col-md-6">
									<label for="age">Age</label>
									<input type="text" value="" placeholder="Age" class="form-control" id="age">
								</div>

								<div class="form-group col-md-6" id="dept">
									<label>部门</label>
									<select class="form-control" id="deptid">
										<!-- 				    	<option value="1">**部</option> -->
									</select>
								</div>
								<div class="form-group col-md-6">
									<label for="address">地址</label>
									<textarea placeholder="Address" class="form-control" id="address" rows="3"	></textarea>
								</div>

								<div class="form-check col-md-12 mb-2">
									<div class="text-left">
										<div class="custom-control custom-checkbox">
											<input class="custom-control-input" type="checkbox" id="ex-check-2">
											<label class="custom-control-label" for="ex-check-2">确认</label>
										</div>
									</div>
								</div>
								<div class="form-group col-md-6 mb-3">
									<input type="button" id="update" class="btn btn-primary btn-lg" value="Update"/>
								</div>
							</div>
						</form>
						<!-- Alerts-->
						<div class="alert alert-success alert-dismissible fade show" id="div_1"  role="alert">
							<strong>Updated Successfully!</strong>
							<button type="button" class="close" data-dismiss="alert" aria-label="Close">
								<span aria-hidden="true">×</span>
							</button>
						</div>
						<!-- /Alerts-->
					</div>
				</div>
				<!-- /Widget Item -->
			</div>
		</div>

			<!-- /Main Content -->
			<!--Copy Rights-->
			<div class="container">
				<div class="d-sm-flex justify-content-center">
					<span class="text-muted text-center d-block d-sm-inline-block">天码行空 © 2020 </span>
				</div>
			</div>
			<!-- /Copy Rights-->
		</div>
		<!-- /Page Content -->
	</div>
	<!-- Back to Top -->
	<a id="back-to-top" href="#" class="back-to-top">
		<span class="ti-angle-up"></span>
	</a>

<!-- /Back to Top -->
<!-- Jquery Library-->
<script src="../js/jquery-3.2.1.min.js"></script>
<!-- Popper Library-->
<script src="../js/popper.min.js"></script>
<!-- Bootstrap Library-->
<script src="../js/bootstrap.min.js"></script>
<!-- Datatable  -->
<script src="../datatable/jquery.dataTables.min.js"></script>
<script src="../datatable/dataTables.bootstrap4.min.js"></script>

<!-- Custom Script-->
<script src="../js/custom.js"></script>
<script src="../js/custom-datatables.js"></script>
<script type="text/javascript">
	function myfun(){
		$("#ex-check-2").prop("checked",false);//设置不选中
		$("#div_1").attr("style","display:none;");//隐藏div
	}
	var doctor;
	$(function() {
		myfun();
		//查询所有部门
		$.ajax({
			url : "/dept/findAllDepts",
			type : "POST",
			success : function(result) {
				//清理之前的部门数据
				$("#dept select").empty();
				$.each(result.data.deptList, function(index, dept) {
					var opt = $("<option></option>").append(
							dept.deptname).attr("value", dept.deptid);
					$("#dept select").append(opt);
				});
			}
		});
		//清理之前的部门数据
		//$("#dept select").empty();

		var name=document.getElementById("username").innerText;
		$.ajax({
			url:"/doctor/findname",
			type: "POST",
			data:{
				"username":name
			},
			success: function (result) {
				if(result.code=200){
					 doctor=result.data.doctor;
					//console.log(result.data.doctor);
					$("#name").attr("value", doctor.name);
					$("#age").attr("value", doctor.age);
					$("#sex").val(doctor.sex); //设置Select的Value值为BMW的项选中
					$("#idnumber").attr("value", doctor.idnumber);
					$("#address").text(doctor.address);
					$("#deptid").val(doctor.depts.deptid);
					//$("#deptName").attr("value", doctor.name);//部门$(‘option:selected’, ‘#select_id’).index(); **获取选中的select的索引

				}
			}
		});
	});
	$("#update").click(function () {
		if($("input[type='checkbox']").is(':checked')==true){  //是否选中复选框
			var json={
				"id":doctor.id,
				"name":document.doctor_form.name.value,
				"idnumber":document.doctor_form.idnumber.value,
				"sex":document.doctor_form.sex.value,
				"age":document.doctor_form.age.value,
				"address":document.doctor_form.address.value,
				"depts":{
					"deptid":document.doctor_form.deptid.value
				}
			}
			console.log(json);
			$.ajax({
				url:"/doctorUser/update",
				type:"post",
				dataType: 'json',
				data: JSON.stringify(json),//转字符串
				contentType: "application/json;charsetset=UTF-8",
				success:function (result) {
					if(result.code=200){
						$("#div_1").attr("style","display:block;");//显示div
						setTimeout(myfun,3000);
					}
				}
			});
		}else{

			alert("请确认！");
		}
	});


</script>
</body>
</html>